package de.mk.model;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;


public class Picture implements Comparable<Picture>, MouseListener {

	private int width = 100;
	private int height = 100;

	private int xPosition = -1;
	private int yPosition = -1;

	private int position = 0;
	

	public enum State {
		uncovered, hidden, unvisible
	}

	public State state =  State.uncovered;

	public Picture() {		
	
	}

//	private void calcXPosition() {
//		int numberOfRows = (int) Math.sqrt(numOfCards);
//		xPosition = position % numberOfRows * getWidth();
//	}
//
//	private void calcYPosition() {
//		yPosition = getRow(position) * getHeight();
//	}
//
//	private int getRow(int position) {
//		int numberOfRows = (int) Math.sqrt(numOfCards);
//		int row = position / numberOfRows;
//		return row;
//	}

	public State getState() {
		return state;
	}

	public void setState(State state1) {
		state = state1;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getxPosition() {
//		if (xPosition == -1) {
//			calcXPosition();
//		}
		return xPosition;
	}

	public void setxPosition(int xPosition) {
		this.xPosition = xPosition;
	}

	public int getyPosition() {
//		if (yPosition == -1) {
//			calcYPosition();
//		}
		return yPosition;
	}

	public void setyPosition(int yPosition) {
		this.yPosition = yPosition;
	}

	@Override
	public int compareTo(Picture o) {

		if (this.position < o.position) {
			return -1;
		}

		if (this.position > o.position) {
			return 1;
		}
		return 0;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println(getState().toString());
		
		switch (state) {
		case hidden:
			setState(State.uncovered);
		case uncovered:
			setState(State.hidden);
		case unvisible:
			setState(State.unvisible);
		}
		System.out.println(state.toString());
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
//		switch (getState()) {
//		case hidden:
//			setState(State.uncovered);
//		case uncovered:
//			setState(State.hidden);
//		case unvisible:
//			setState(State.unvisible);
//		}
//		System.out.println(getState().toString());
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
